from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.contenttypes.models import ContentType
from django.template import RequestContext
from django.http import HttpResponseRedirect

def delete(request, action, section, app_label, model, id, template='backend/delete_confirmation.html'):
    ct = get_object_or_404(ContentType, app_label=app_label, model=model)
    obj = get_object_or_404(ct.model_class(), pk=id)
    
    if request.method == 'POST':
        obj.delete()
        return HttpResponseRedirect(request.session.get('return_path'))
        
    
    return render_to_response(template, {
        'o': obj,
        'section': section,
        'action': action,
    }, RequestContext(request))